package com.sike.netty.im.client.handler;

import com.sike.netty.im.client.event.CustomEvent;
import com.sike.netty.im.client.event.EventFactory;
import com.sike.netty.im.client.event.MainMenuEvent;
import com.sike.netty.im.client.service.BeanFactory;
import com.sike.netty.im.client.service.LoginService;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.Scanner;


/**
 * 主菜单 Handler
 *
 * @author chenssy
 * @date 2023/09/18
 */
public class MainMenuHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof MainMenuEvent) {
            new Thread(() -> {
                LoginService loginService = (LoginService) BeanFactory.getServiceBean(LoginService.class);
                // 主菜单
                loginService.mainMenu();

                Scanner scanner = new Scanner(System.in);
                System.out.print("请输入你要操作的指令：");
                String event = scanner.nextLine();

                CustomEvent customEvent = EventFactory.getCustomEvent(event);
                ctx.fireUserEventTriggered(customEvent);
            }).start();
        } else {
            super.userEventTriggered(ctx,evt);
        }
    }
}
